package com.java.admin.makeanappointment.controller;

import com.github.pagehelper.PageInfo;
import com.java.admin.makeanappointment.service.MakeanAppointmentService;
import com.java.database.entity.Makeanappointmentinfo;
import com.java.database.entity.Servicetype;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MakeanAppointmentController {

    @Autowired
    private MakeanAppointmentService makeanAppointmentService;
    /**
     *  添加预约
     * @param makeanappointmentinfo
     * @return
     */
    @RequestMapping(value = "/addAppointment",produces="text/html;charset=UTF-8;")
    @ResponseBody
    public int addAppointment(Makeanappointmentinfo makeanappointmentinfo){
        int i = makeanAppointmentService.addAppointment(makeanappointmentinfo);
        return i;
    }
    /**
     *  删除预约
     * @param makeAnAppointMentId
     * @return
     */
    @RequestMapping("/delAppointment")
    public String delAppointment(@RequestParam(defaultValue = "")String makeAnAppointMentId){
        makeanAppointmentService.delAppointment(makeAnAppointMentId);
        return "redirect:/admin/makeanappointment.html";
    }
    /**
     *  修改预约
     * @param makeAnAppointMent
     * @return
     */
    @RequestMapping("/uplAppointment")
    public String upAppointment(Makeanappointmentinfo makeAnAppointMent){
        makeanAppointmentService.upAppointment(makeAnAppointMent);
        return "redirect:/admin/makeanappointment.html";
    }
    /**
     * 查询所有的服务
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryAllServiceType")
    public List<Servicetype> queryServiceType() {
        List<Servicetype> servicetypes = makeanAppointmentService.queryAllServicetype();
        if(servicetypes==null){
            throw new RuntimeException("没有数据啊");
        }
        return servicetypes;
    }
    /**
     *  查询所有未受理的预约信息
     * @return  返回装有所有未受理的预约信息的json字符串
     */
    @ResponseBody
    @RequestMapping(value = "/queryAllAppointment")
    public PageInfo queryAllAppointment(String pageNum,@RequestParam(defaultValue = "")String condition){
        //  调用service方法查询所有的未处理预约信息
        PageInfo pageInfo = makeanAppointmentService.queryAll(pageNum, condition);
        return pageInfo;
    }
    @ResponseBody
    @RequestMapping(value = "/queryAppointmentById")
    public Makeanappointmentinfo queryAppointmentById(@RequestParam(defaultValue = "") String makeanappointmentid){
        Makeanappointmentinfo makeanappointmentinfo = makeanAppointmentService.queryMakeanAppointmentById(makeanappointmentid);
        return makeanappointmentinfo;
    }

}
